package cn.wolfcode.p2p.base.domain;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter@Setter
public class VideoAuth extends BaseAudit{
    private OrderTime orderTime;//预约时间段对象
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date orderDate;//预约日期

    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        map.put("completeOrderTime",getcompleteOrderTime());
        map.put("username",getApplier().getUsername());
        map.put("id",id);
        try {
            return new ObjectMapper().writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

    private String getcompleteOrderTime() {
        return DateFormat.getDateInstance().format(getOrderDate()) +" "+orderTime.getBegin()+"-"+orderTime.getEnd();
    }


}